const {baseUrl} = require("../config");

 function request(url, method, params, callback) {
    let config = {
        url: baseUrl + url,
        method,
        data:params,
    }
    return wx.request({
        ...config,
        header: {},
        success(res) {
            callback(res);

        },
        fail(res) {
            console.log(res);
            wx.showToast({
                title: "request failed ,please check the networks",
                icon: 'none'
            })
        }
    })
}

export function get(url,params) {
     return new Promise((resolve, reject) => {
         request(url,"GET",params,resolve)
         }
     )
}
export function post(url,params,callback) {
    request(url,"POST",params,callback)
}
export function del(url,params,callback) {
    request(url,"DELETE",params,callback)
}
export function put(url,params,callback) {
    request(url,"PUT",params,callback)
}
export function update(url,params,callback) {
    request(url,"UPDATE",params,callback)
}
